package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.atguigu.gmall.product.service.SpuImageService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/8/27 3:18
 */
@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;
    @Autowired
    private SpuImageService spuImageService;
    @GetMapping("baseTrademark/{pageNum}/{pageSize}")
    public Result baseTrademarkPage(@PathVariable("pageNum") Long pageNum,
                                    @PathVariable("pageSize") Long pageSize){
        Page<BaseTrademark> trademarkPage = new Page<>(pageNum, pageSize);
        Page<BaseTrademark> result = baseTrademarkService.page(trademarkPage);

        return Result.ok(result);
    }
    // 新增品牌
    @PostMapping("/baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    //获取品牌详情
    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTrademark(@PathVariable("id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
    //修改品牌
    @PutMapping("/baseTrademark/update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
    //删除品牌
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result removeBaseTrademark(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
    //获取品牌列表
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        return Result.ok(baseTrademarkService.list());
    }
    //根据spuId获取品牌列表
    @GetMapping("/spuImageList/{spuId}")
    public Result getTrademarkListBySpuId(@PathVariable("spuId") Long spuId){
        return Result.ok(spuImageService.list(new QueryWrapper<SpuImage>().eq("spu_id", spuId)));
    }
}
